﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Breeds
{
    public class BreedUpdRequestHandler : IRequestHandler<BreedUpdRequestModel, APIResult>
    {
        private IBaseRepository<Breed> breedRepository;
        private readonly IMapper mapper;
        public BreedUpdRequestHandler(IBaseRepository<Breed> breedRepository, IMapper mapper)
        {
            this.breedRepository = breedRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(BreedUpdRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.UpdSuccess;
            result.Msg = "编辑成功";

            Breed role = mapper.Map<Breed>(request);
            breedRepository.Update(role);

            return Task.FromResult(result);
        }
    }
    public class BreedUpdRequestModel:IRequest<APIResult>
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        public string Variety { get; set; }
        public string Source { get; set; }
        public int FeedingDays { get; set; }
        public string FeedingBrand { get; set; }
        public string FeedingName { get; set; }
        public DateTime SaleDate { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
